﻿using MediatR;
using Traceability.Commont.Domains.ScratchTheFat;
using Traceability.Commont.DTOs.CommontFiles;
using Traceability.Commont.Infrastructures.Interfaces;
namespace U.Enterprise.Api.Applications.SalesWeighingEXE
{
    public class SalesWeighingHtmlHandler : IRequestHandler<SalesWeighingHtmlCommond, PageDTO<SalesWeighing>>
    {

        private readonly IBateRepository<SalesWeighing> SalesWeighing;

        public SalesWeighingHtmlHandler(IBateRepository<SalesWeighing> SalesWeighing)
        {
            this.SalesWeighing = SalesWeighing;
        }



        public  async Task<PageDTO<SalesWeighing>> Handle(SalesWeighingHtmlCommond request, CancellationToken cancellationToken)
        {

            try
            {
                var list = new PageDTO<SalesWeighing>() { pageCount = 0, Lists = new List<SalesWeighing>(), totalCount = 0 };
                var query = SalesWeighing.GetAll().ToList();
                list.totalCount = query.Count;
                list.pageCount = (int)Math.Ceiling(query.Count * 1.0 / request.PageSize);
                query = query.OrderBy(x => x.SalesWeighingID).Skip(request.Pageindex-1).Take(request.PageSize).ToList();
                list.Lists = query;

                return list;

            }
            catch (Exception)
            {

                throw;
            }
            



        }
    }
}
